<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Base\Item;
use App\Models\Game\PlayerGamedata;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

/**
 * 表单api数据.
 */
class ApiController extends Controller
{
    /**
     * [player 角色列表].
     *
     * @Author   王文凡
     * @DateTime 2018-04-11
     *
     * @version  1.0
     *
     * @param Request $request
     *
     * @return array
     */
    public function player(Request $request)
    {
        $server_id = $request->get('father_value');
        $q = $request->get('q');
        setDB($server_id);
        $page_data = PlayerGamedata::where('name', 'like', "%$q%")->paginate(null, ['id', 'name as text'])->toArray();
        foreach ($page_data['data'] as $key => &$value) {
            $value['id'] = (string) $value['id'];
        }

        return $page_data;
    }

    /**
     * [getItem 道具列表].
     *
     * @Author   王文凡
     * @DateTime 2018-04-28
     *
     * @version  1.0
     *
     * @param Request $request [description]
     *
     * @return Model
     */
    public function getItem(Request $request)
    {
        $q = $request->get('q');

        return Item::where('name', 'like', "%$q%")->paginate(null, ['item_no as id', 'name as text']);
    }
}
